home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
web
/
noweb
/
src
/
icon
/
noindex.icn
< prev
next >
Wrap
Text File
|
1995-02-24
|
2KB
|
88 lines
#line 6 "noindex.nw"
procedure main(args)
if *args ~= 1 then
write(&errout, "Usage: nomkidx basename")
else {
in := get(args)
if in[-4:0] == ".tex" then in[-4:0] := ".aux"
else if not (in[-4:0] == ".aux") then in ||:= ".aux"
gobble(in, idx := [])
f := open(in[1:-4] || ".nwi", "w") | stop("Cannot write ", in[1:-4] || ".nwi")
last := ""
every out := stripcount(!alphasort(idx)) do
write(f, last ~== out) & last := out
close(f)
}
return
end
#line 23 "noindex.nw"
procedure gobble(name, idx)
static count
initial count := 0
in := open(name) |
#line 40 "noindex.nw"
{ write(&errout, "No file ", name, "."); return }
#line 27 "noindex.nw"
while line := read(in) do
line ?
if ="\\@input{" & name := tab(upto('}')) & move(1) & pos(0) then
gobble(name, idx)
else if ="\\nwixadds{" then
put(idx, right(count +:= 1, 6, "0") || " " || tab(0))
return
end
#line 36 "noindex.nw"
procedure stripcount(s)
s ? { tab(many(&digits)); tab(many(' ')); return "\\nwixaddsx{" || tab(0) }
end
#line 42 "noindex.nw"
procedure alphasort(x)
t := table()
every s := !x do t[s] := sortkey(s)
t := sort(t, 2)
l := []
every put(l, (!t)[1])
return l
end
#line 51 "noindex.nw"
procedure sortkey(s)
local count
map(s) ? {
count := tab(many(&digits))
tab(many(' '))
if ="c}" then return firstkey() || "\n" || count
else if ="i}" then return firstkey() || "\n" || count
else stop("not chunk or index")
}
end
#line 62 "noindex.nw"
procedure firstkey()
="{{" | stop("bad index or chunk format")
s := (remove_control_sequences() ? tab(bal('}', '{', '}') | 0))
return alphabet(s) || "\n" || s
end
#line 68 "noindex.nw"
procedure alphabet(s)
static keep
initial keep := &lcase ++ ' \t'
r := ""
s ? {
while tab(upto(keep)) do
if tab(many(' \t')) then
r ||:= " "
else
r ||:= tab(many(&lcase)) | stop("This can't happen")
}
r ? { tab(many(' ')) ; return tab(0) } # strip leading blanks
end
#line 82 "noindex.nw"
procedure remove_control_sequences()
s := ""
while s ||:= tab(upto('\\')) do {
="\\"
tab(many(&letters)) | move(1) # skip
tab(many(' \t'))
}
return s || tab(0)
end